﻿<style>
body {
	margin: 0 auto;
	width: 70%;
	font: 100% Georgia, "Times New Roman", Times, serif;
}
h2 {
	color:red;
	font-weight: normal;
}
table { 
	border-collapse: collapse; 
	border: none; 
	width: 400px; 
} 
td { 
	border: solid #000 1px;
	width: 100px; 
} 
</style>
<table><tr><td>DES</td><td>INFO</td><td>Whois</td></tr>
<?php
if(empty($_GET['ip'])){
    $IP=$_SERVER['REMOTE_ADDR'];
}else{
	$IP=$_GET['ip'];
}
exec("sudo vtysh -c \"sh ip bgp $IP\"",$info);
$arr = explode(" ",$info[0]); 
$CDIR=end($arr);
if(strstr($CDIR,"0.0.0.0")) {
echo "CDIR:0.0.0.0/0";
echo "<br>ASN:0";
}
else
{
echo "<tr><td>CDIR</td><td><a href=http://bgp.he.net/net/".$CDIR." target=_blank>".$CDIR."</a></td><td><a href=http://bgp.he.net/net/".$CDIR."#_whois target=_blank>WHOIS</a></td></tr>";
$arr1 = explode(" ",$info[3]); 
$ASN=end($arr1);
echo "<tr><td>ASN</td><td><a href=http://bgp.he.net/AS".$ASN." target=_blank>".$ASN."</a></td><td><a href=http://bgp.he.net/AS{$ASN}#_whois target=_black>WHOIS</a></td></tr>";
echo "<table>";
}
?>
<br>
<form action='' method='get'>
<input type='text' name='ip'>
<input type='submit' value='Submit',name='sub'>
</form>